/**
 * 
 */
package com.pactera.integral.security;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.springframework.security.core.Authentication;
import org.springframework.security.core.context.SecurityContextHolder;
import org.springframework.security.web.authentication.logout.SecurityContextLogoutHandler;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.ResponseBody;

import com.pactera.integral.common.web.GenericController;
import com.pactera.integral.common.web.Response;


/**
 * @author User
 * 登出功能
 */
@Controller
public class UserLogoutController extends GenericController {

	@RequestMapping(value="/logout", method = RequestMethod.GET)
	@ResponseBody
	public Response logoutAction (HttpServletRequest request, HttpServletResponse response) {
		Authentication auth = SecurityContextHolder.getContext().getAuthentication();
		if (auth != null){    
			new SecurityContextLogoutHandler().logout(request, response, auth);
		}
		String message = "logout";
		return this.normal(message);
	}
}
